/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            housekeepingServInfo: {
                housekeepingServs: [],
                total: 0,
                records: 1,
                moreCondition: false,
                servId: '',
                componentShow: 'housekeepingServ',
                housekeepingTypes: [],
                repairWays: [],
                conditions: {
                    repairWay: '',
                    servName: '',
                    hktId: '',
                    shopId: ''
                }
            }
        },
        _initMethod: function () {
            $that.housekeepingServInfo.conditions.shopId = vc.getCurrentCommunity().shopId;
            $that._listHousekeepingServs(DEFAULT_PAGE, DEFAULT_ROWS);
            $that._listHousekeepingTypes(1, 50);
            vc.getDict('housekeeping_serv', "repair_way", function (_data) {
                $that.housekeepingServInfo.repairWays = _data;
            });
        },
        _initEvent: function () {
            vc.on('housekeepingServ', 'listHousekeepingServ', function (_param) {
                $that.housekeepingServInfo.componentShow = 'housekeepingServ';
                $that._listHousekeepingServs(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listHousekeepingServs(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listHousekeepingTypes: function (_page, _rows) {
                let param = {
                    params: {
                        page: _page,
                        row: _rows,
                        typeCd: 1001,
                        shopId: vc.getCurrentCommunity().shopId
                    }
                };
                //发送get请求
                vc.http.apiGet('/housekeepingType.queryHousekeepingType',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.housekeepingServInfo.housekeepingTypes = _json.data;
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _listHousekeepingServs: function (_page, _rows) {
                $that.housekeepingServInfo.conditions.page = _page;
                $that.housekeepingServInfo.conditions.row = _rows;
                var param = {
                    params: $that.housekeepingServInfo.conditions
                };
                param.params.servName = param.params.servName.trim();
                //发送get请求
                vc.http.apiGet('/housekeepingServ.queryHousekeepingServ',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.housekeepingServInfo.total = _json.total;
                        $that.housekeepingServInfo.records = _json.records;
                        $that.housekeepingServInfo.housekeepingServs = _json.data;
                        console.log($that.housekeepingServInfo.housekeepingServs);
                        vc.emit('pagination', 'init', {
                            total: $that.housekeepingServInfo.records,
                            dataCount: $that.housekeepingServInfo.total,
                            currentPage: _page
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _openAddHousekeepingServModal: function () {
                 //跳转到浏览器
                 vc.jumpToPage('/#/pages/housekeeping/addHousekeepingServ');
            },
            _openEditHousekeepingServModel: function (_housekeepingServ) {
                 //跳转到浏览器
                 vc.jumpToPage('/#/pages/housekeeping/editHousekeepingServ?servId='+_housekeepingServ.servId);
            },
            _openDeleteHousekeepingServModel: function (_housekeepingServ) {
                vc.emit('deleteHousekeepingServ', 'openDeleteHousekeepingServModal', _housekeepingServ);
            },
            _queryHousekeepingServMethod: function () {
                $that._listHousekeepingServs(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _resetHousekeepingServMethod: function () {
                $that.housekeepingServInfo.conditions.servName = "";
                $that.housekeepingServInfo.conditions.hktId = "";
                $that.housekeepingServInfo.conditions.repairWay = "";
                $that._listHousekeepingServs(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _openAddHousekeepingFeeConfigRel: function (_servId, _servName) {
                vc.emit('addHousekeepingFeeConfigRel', 'openAddHousekeepingFeeConfigRelModel', {_servId, _servName});
            },
            _openHousekeepingFeeConfigManageRel: function (_housekeepingServ) {
                //跳转到浏览器
                vc.jumpToPage('/#/pages/housekeeping/housekeepingServFeeConfigManageRel?servId=' + _housekeepingServ.servId + '&servName=' + _housekeepingServ.servName);
            },
            _openHousekeepingServUser: function (_housekeepingServ) {
                //跳转到浏览器
                vc.jumpToPage('/#/pages/housekeeping/housekeepingServUserManage?servId=' + _housekeepingServ.servId + '&servName=' + _housekeepingServ.servName);
            },
            _viewServDetail: function (_serv) {
                vc.emit('viewQrCode', 'openQrCodeModal', {
                    title: _serv.servName,
                    url: _serv.pageUrl,
                    remark: '手机扫码查看家政服务',
                });
            },
            _moreCondition: function () {
                if ($that.housekeepingServInfo.moreCondition) {
                    $that.housekeepingServInfo.moreCondition = false;
                } else {
                    $that.housekeepingServInfo.moreCondition = true;
                }
            }
        }
    });
})(window.vc);
